package generateConnections;

import java.util.ArrayList;

import logging.Logger;
import networkInterface.NetworkInterfaceBase;
import object.Node;

public class GenerateShortestConnection extends GenerateConnectionBase{

	@Override
	public void genConnections(ArrayList<Node> nodes, Node node) {
//		if(nodes.size() < 2)
//			return;
		for( NetworkInterfaceBase i : node.getInterfaces() )
		{
			int shortest = -1;
			NetworkInterfaceBase hold = null; 
			for( NetworkInterfaceBase j: i.getConnectableInterfaces(nodes) )
			{
				if( j.getNode().getLength(node) < shortest || shortest == -1 )
					hold = j;
			}
			if( hold != null )
			{
				try {
					i.addConnection(hold);
				} 
				catch (Exception e) {
					Logger.getInstance().log(Logger.WARNING, "Unexpectedly could not create interface connection " + e.getMessage());
				} 
			}
			
		}
	
	}	
	
	
}
